'use strict';
/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  /**
   * 业务
   */
  router.get('/api/decodePayNotify', controller.payment.wxPay.decodePayNotify)
  // banner
  router.get('/api/banner/list', controller.business.banner.list);
  router.resources('banner', '/api/banner', controller.business.banner);
  // 资讯收藏
  router.get('/api/collection/product', controller.business.collection.collectionProduct);
  router.resources('Collection', '/api/collection', controller.business.collection);
  // 产品分类
  router.get('/api/productCategory/list', controller.business.productCategory.list);
  router.resources('productCategory', '/api/productCategory', controller.business.productCategory);
  // 产品
  router.get('/api/product/list', controller.business.product.list);
  router.get('/api/product/tree', controller.business.product.tree);
  router.resources('product', '/api/product', controller.business.product);
  // 景点
  router.get('/api/ticketShop/list', controller.business.ticketShop.list);
  router.post('/api/ticketShop/login', controller.business.ticketShop.login);
  router.resources('ticketShop', '/api/ticketShop', controller.business.ticketShop);
  router.get('/api/ticketLine/list', controller.business.ticketLine.list);
  router.resources('ticketLine', '/api/ticketLine', controller.business.ticketLine);
  router.get('/api/ticketLineRecord/list', controller.business.ticketLineRecord.list);
  router.resources('ticketLineRecord', '/api/ticketLineRecord', controller.business.ticketLineRecord);
  /**
   * 购物车
   */
  router.get('/api/cart/list', controller.business.cart.list);
  router.post('/api/cart/batchDelete', controller.business.cart.batchDelete);
  router.post('/api/cart/statusAll', controller.business.cart.updateCartStatusAll);
  router.resources('cart', '/api/cart', controller.business.cart);
  /**
   * 用户
   */
  router.get('/api/user/wx/getUserQrCode', controller.business.user.getUserQrCode);
  router.post('/api/user/wx/login', controller.business.user.wxLogin);
  // 用户
  router.get('/api/user/list', controller.business.user.list);
  // 我的下级用户
  router.get('/api/user/children', controller.business.user.getChildrenList);
  router.resources('user', '/api/user', controller.business.user);
  router.resources('address', '/api/address', controller.business.address);

  /**
   * 订单
   */
  // 获取订单详情
  router.get('/api/order/detail', controller.business.order.detail);
  // 取消订单
  router.post('/api/order/cancel', controller.business.order.cancel);
  // 申请退款
  router.post('/api/order/refund', controller.business.order.refund);
  router.post('/api/order/refund/confirm', controller.business.order.refundConfirm);
  router.resources('order', '/api/order', controller.business.order);

  router.get('/api/orderCode/list', controller.business.orderCode.list);
  router.post('/api/orderCode/verify', controller.business.orderCode.verify);
  router.get('/api/orderCode/dailyStats', controller.business.orderCode.dailyStats);
  router.resources('orderCode', '/api/orderCode', controller.business.orderCode);
  // 优惠券
  router.get('/api/coupon/list', controller.business.coupon.list);
  router.post('/api/coupon/distribute', controller.business.coupon.distribute);
  router.resources('coupon', '/api/coupon', controller.business.coupon);
  // 用户优惠券
  router.get('/api/userCoupon/list', controller.business.userCoupon.list)
  router.get('/api/userCoupon/user', controller.business.userCoupon.getUserCoupons)
  router.get('/api/userCoupon/available', controller.business.userCoupon.getAvailableCoupons)
  router.resources('userCoupon', '/api/userCoupon', controller.business.userCoupon);
  /**
   * 评论
   */
  router.resources('comment', '/api/comment', controller.business.comment);
  /**
   * 支付
   */
  // 创建支付订单
  router.post('/api/payment/wx', controller.payment.wxPay.createPayment);
  router.post('/api/wxPay/paymentWxNotify', controller.payment.wxPay.paymentWxNotify);
  router.post('/api/wxPay/refundWxNotify', controller.payment.wxPay.refundWxNotify);
  router.post('/api/wxPay/transferWxNotify', controller.payment.wxPay.transferWxNotify);
  /**
   * 反馈管理
   */
  router.resources('feedback', '/api/feedback', controller.business.feedback);
  router.get('/api/distribution/list', controller.business.distribution.list);
  router.resources('distribution', '/api/distribution', controller.business.distribution);
  router.get('/api/balanceRecord/todayTotal', controller.business.balanceRecord.todayTotal);
  router.post('/api/balanceRecord/withdraw', controller.business.balanceRecord.withdraw)
  router.get('/api/balanceRecord/list', controller.business.balanceRecord.list);
  router.resources('balanceRecord', '/api/balanceRecord', controller.business.balanceRecord);
  router.post('/api/balanceRecord/withdraw', controller.business.balanceRecord.withdraw);
  router.get('/api/post/list', controller.business.post.list);
  router.resources('post', '/api/post', controller.business.post);
  router.get('/api/postComment/list', controller.business.postComment.list);
  router.resources('postComment', '/api/postComment', controller.business.postComment);
  router.get('/api/postLike/list', controller.business.postLike.list);
  router.resources('postLike', '/api/postLike', controller.business.postLike);
  /**
   * 管理
   */
  // 上传文件
  router.post('/api/upload/file', controller.common.upload.cos);
  router.get('/api/file/list', controller.common.file.list);
  router.resources('file', '/api/file', controller.common.file);
  // ----------------------租户----------------------------//
  // 租户登录/system/auth/login
  router.post('/api/system/auth/login', controller.system.systemUser.login)
  // 获取租户信息和权限
  router.get('/api/system/auth/get-permission-info', middleware.auth(), controller.system.systemUser.getUserInfo)
  router.resources('/api/system/user', middleware.auth(), controller.system.systemUser);
  // 租户菜单
  router.get('/api/system/menu/tree', middleware.auth(), controller.system.systemMenu.tree);
  router.resources('/api/system/menu', middleware.auth(), controller.system.systemMenu);
  // 角色
  router.get('/api/system/role/list', middleware.auth(), controller.system.systemRole.list);
  router.resources('/api/system/role', middleware.auth(), controller.system.systemRole);
  // 权限
  router.get('/api/system/permission/list-user-roles', middleware.auth(), controller.system.systemPermission.getUserRoles);
  router.post('/api/system/permission/assign-user-role', middleware.auth(), controller.system.systemPermission.updateUserRoles);
  router.get('/api/system/permission/list-role-menus', middleware.auth(), controller.system.systemPermission.listRoleMenus);
  router.post('/api/system/permission/assign-role-menu', middleware.auth(), controller.system.systemPermission.updateRoleMenus);
};
